<template>
  <div>
    <div id="user_info">
      <div class="inp_box">
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="80px"
          class="demo-ruleForm"
        >
          <el-form-item label="昵称" prop="nick">
            <el-input type="text" v-model="ruleForm.nick" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="联系电话" prop="phone">
            <el-input type="text" v-model="ruleForm.phone" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="电子邮箱" prop="email">
            <el-input type="text" v-model="ruleForm.email" autocomplete="off"></el-input>
          </el-form-item>
          <div class="go_reg"></div>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">编辑保存</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="upload_box">
        <AvatarUpload></AvatarUpload>
        <p>仅支持JPG格式，文件小于2M</p>
      </div>
    </div>
    <div id="get_s_num">
      <button class="s_num_button">点击申请注册序列号</button>
      <input type="text" :value="s_num" readonly id="s_num_inp" />
      <button class="opt_btn copy" @click="copy">点击复制</button>
      <button class="opt_btn send">发送短信</button>
      <button class="opt_btn send">发送邮件</button>
    </div>
  </div>
</template>

<script>
import AvatarUpload from "../components/avatar_upload.vue";
import { log } from "util";
export default {
  name: "user_info",
  components: {
    AvatarUpload
  },
  data() {
    var validate_nick = (rule, value, callback) => {
      if (value === "") {
      } else {
      }
      callback();
    };
    var validate_phone = (rule, value, callback) => {
      if (value === "") {
      } else {
      }
      callback();
    };
    var validate_email = (rule, value, callback) => {
      if (value === "") {
      } else {
      }
      callback();
    };
    return {
      s_num:'',
      ruleForm: {
        nick: "",
        phone: "",
        email: ""
      },
      rules: {
        nick: [{ validator: validate_nick, trigger: "blur" }],
        phone: [{ validator: validate_phone, trigger: "blur" }],
        email: [{ validator: validate_email, trigger: "blur" }]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$message({
            message: "已保存更新",
            type: "success"
          });
        } else {
          return false;
        }
      });
    },

    copy() {
      // 复制到粘贴板
      let inp = document.querySelector("#s_num_inp");
      inp.select();
      document.execCommand("Copy", "false", null);
      if (document.execCommand("Copy", "false", null)) {
        //如果复制成功
        this.$message({
          message: "恭喜你，复制成功了",
          type: "success"
        });
      } else {
        //如果复制失败
        this.$message({
          message: "抱歉，复制失败了",
          type: "warning"
        });
      }
    }
  }
};
</script>

<style lang="scss">
@import "../_theme.scss";
#user_info {
  display: flex;
  justify-content: center;
  width: 1000px;
  box-shadow: 2px 2px 20px gray, -2px 2px 10px gray;
  background-color: #fff;
  margin: 26px auto;
  border-radius: 6px;
  > .inp_box,
  .upload_box {
    margin: 40px;
  }
  > .upload_box {
    > .avatar-uploader {
      border-radius: 50%;
      > .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 50%;
        cursor: pointer;
        position: relative;
        overflow: hidden;
      }
    }
    > p {
      margin: 10px;
      color: $default_color;
      font-size: 12px;
      text-align: center;
    }
  }
}
#get_s_num {
  display: flex;
  height: 200px;
  width: 1000px;
  box-shadow: 2px 2px 20px gray, -2px 2px 10px gray;
  background-color: #fff;
  margin: 30px auto;
  border-radius: 6px;
  justify-content: center;
  align-items: center;
  > #s_num_inp {
    text-align: center;
    height: 40px;
    width: 240px;
    border: none;
    border-radius: 6px;
    background-color: rgb(211, 211, 211);
    margin: 20px;
    font-size: 18px;
    outline: none;
  }
  > .s_num_button {
    cursor: pointer;
    height: 42px;
    padding: 0px 20px;
    background-color: rgb(255, 115, 0);
    border: none;
    color: white;
    border-radius: 6px;
    outline: none;
    transition: all 0.2s;
    &:hover {
      background-color: rgb(255, 145, 0);
    }
  }
  > .opt_btn {
    cursor: pointer;
    height: 30px;
    padding: 0 20px;
    background-color: rgb(194, 10, 240);
    border: none;
    color: white;
    border-radius: 6px;
    outline: none;
    transition: all 0.2s;
    margin: 10px;
    &:hover {
      background-color: rgb(231, 96, 255);
    }
  }
}
</style>